//
//  RAPStatusPictureCell.swift
//  COPYCAT-Weibo
//
//  Created by 闫萌 on 1/2/16.
//  Copyright © 2016 RendezvousAuParadis. All rights reserved.
//

import UIKit

class RAPStatusPictureCell: UICollectionViewCell {
    
    var picURL: RAPStatusPictureModel? {
        didSet {
            if let url = picURL?.thumbnail_pic {
                picView.sd_setImageWithURL(NSURL(string: url), placeholderImage: UIImage(named: "timeline_image_placeholder"))
            }
        }
    }
    
    var isGIF: Bool? {
        didSet {
            
            guard let opIsGIF = isGIF else {
                return
            }
            
            if opIsGIF { // 是gif，不隐藏
                gifIcon.hidden = false
            } else { // 不是gif，隐藏
                gifIcon.hidden = true
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(picView)
        addSubview(gifIcon)
        
        picView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self)
        }
        
        gifIcon.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView)
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 懒加载控件
    lazy var picView: UIImageView = {
        let picView = UIImageView()
        picView.contentMode = .ScaleAspectFill
        picView.clipsToBounds = true
        return picView
    }()
    
    lazy var gifIcon: UIImageView = {
        let gifIcon = UIImageView(image: UIImage(named: "timeline_image_gif"))
        gifIcon.hidden = true // 一开始隐藏
        return gifIcon
    }()
    
}
